<?php
// @formatter:off
/**
 * @file WCCaptchaService.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-10-27 18:31:53 +0000 (Sun, 27 Oct 2013) $
 *
 * $Id: WCCaptchaService.php 110 2013-10-27 18:31:53Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/includes/services/WCCaptchaService.php $
 */
// @formatter:on

class WCCaptchaService extends WCService {
	//
	// Class methods.
	public function __construct() {
		parent::__construct();

		$this->_requiredParams["params"][] = "captcha";
	}
	//
	// Public methods
	public function check() {
		if(parent::check()) {
			$this->checkCaptcha();
		}

		return $this->ok();
	}
	//
	// Protected methods.
	protected function checkCaptcha() {
		global $wcCaptcha;

		startCaptcha();

		if(!$this->captcha || $wcCaptcha->check($this->captcha) == false) {
			$this->setError(WC_HTTPERROR_BAD_REQUEST, "The security code entered was incorrect");
		}

		return $this->ok();
	}
	protected function load() {
		$out = false;

		if(parent::load()) {
			$this->_captcha = isset($this->captcha) ? trim($this->captcha) : false;

			$out = true;
		}

		return $out;
	}
}
?>